package com.web.listeners;

import org.testng.ITestResult;
import org.testng.TestListenerAdapter;

import com.app.AppContext;
import com.spira.SpiraTestRecorder;
import com.spira.SpiraTestRun;
import com.spira.SpiraUser;
import com.web.listeners.imp.TestRunFactory;

public class SpiraTestListener extends TestListenerAdapter {
	
	private static SpiraTestRecorder recorder = AppContext.getBean(SpiraTestRecorder.class);
	
	private static SpiraUser user = AppContext.getBean(SpiraUser.class);
    
    @Override
    public void onTestFailure(ITestResult testResult) {
    	
    	sendTestRun(testResult);
    }
	 
	@Override
	public void onTestSuccess(ITestResult testResult) {
		
		sendTestRun(testResult);
	}
	
	private void sendTestRun(ITestResult testResult){
		SpiraTestRun testRun = TestRunFactory.newSpiraTestRun(testResult);
		recorder.sendTestRun(user, testRun);
	}
}
